<%@ page contentType="text/html;charset=utf-8" language="java"
	pageEncoding="UTF-8" import="java.util.Date"%>
<!DOCTYPE html>
<html lang="en">
<head>
<%@include file="/WEB-INF/jsp/common/style.jsp"%>
</head>
<body>
	<div id="wrap">
		<input type="hidden" id="templateId" value="${model.emailTemplate.id}">
		<div class="main_container" id="forms_page">
			<div class="row-fluid">
				<div class="widget widget-padding span12">

					<div class="widget-forms clearfix" style="padding-top: 15px">
						<div class="form-horizontal" id="content">
							<div class="control-group">
								<label class="control-label"><font color="red">*</font>邮件类型:</label>
								<div class="controls">
									<select name="emailType" id="emailType" type="select"
										class="w300 ">
										<option value=""
											<c:if test="${model.emailTemplate.emailType==null}">selected="selected"</c:if>>全部</option>
										<option value="1"
											<c:if test="${model.emailTemplate.emailType==1}">selected="selected"</c:if>>产品流传邮件</option>
										<option value="2"
											<c:if test="${model.emailTemplate.emailType==2}">selected="selected"</c:if>>产品退回邮件</option>
									</select>
								</div>
							</div>

							<div class="control-group">
								<label class="control-label"><font color="red">*</font>邮件模板名称:</label>
								<div class="controls">
									<input name="templateName" id="templateName" maxlength="100"
										type="text" class="w300 tip"
										value="${model.emailTemplate.templateName}" />
								</div>
							</div>


							<div class="control-group">
								<label class="control-label"><font color="red">*</font>邮件主题名称:</label>
								<div class="controls">
									<input name="emailSubject" id="emailSubject" maxlength="100"
										type="text" class="w300 tip"
										value="${model.emailTemplate.emailSubject}" />
								</div>
							</div>
							<div class="control-group">
								<label class="control-label"><font color="red">*</font>通知范围:</label>
								<div class="controls">

									<textarea class="w300" id="receiverUser" rows="5"
										style="height: 100px;">${model.emailTemplate.receiverUser}</textarea>

								</div>
								<span class="controls">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
							</div>
							<div class="control-group">
								<label class="control-label"><font color="red">*</font>邮件内容:</label>
								<div class="controls">

									<textarea class="w300" id="emailContent" rows="5"
										style="height: 100px;">${model.emailTemplate.emailContent}</textarea>

								</div>
								<span class="controls">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
							</div>


						</div>
					</div>

				</div>
			</div>
			<div class="row-fluid">
				<div class="footbtn"> 
				<button class="btn btn-primary" type="submit" onclick="save()">保存</button>
				<button class="btn" type="button" onclick="backIndex()">取消</button>
				</div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	function save() {
		var postData = "templateId=" + $('#templateId').val();

		var emailType = $('#emailType').val();
		if (emailType == '') {
			layer.alert('请选择邮件类型');
			return;
		}
		postData = postData + "&emailType=" + emailType;

		var templateName = $('#templateName').val();
		if (templateName == '') {
			layer.alert('请输入模板名称');
			return;
		}
		postData = postData + "&templateName="
				+ encodeURIComponent(templateName);

		var emailSubject = $('#emailSubject').val();
		if (emailSubject == '') {
			layer.alert('请输入邮件主题');
			return;
		}
		postData = postData + "&emailSubject="
				+ encodeURIComponent(emailSubject);

		var receiverUser = $('#receiverUser').val();
		if (receiverUser == '') {
			layer.alert('请输入通知范围');
			return;
		}
		postData = postData + "&receiverUser="
				+ encodeURIComponent(receiverUser);

		var emailContent = $('#emailContent').val();
		if (emailContent == '') {
			layer.alert('请输入邮件内容');
			return;
		}
		postData = postData + "&emailContent="
				+ encodeURIComponent(emailContent);

		layer.load(1, {
			shade : [ 0.5, '#fff' ]
		});
		//alert(postData);
		$.ajax({
			type : "POST",
			url : "save",
			data : postData,
			contentType : "application/x-www-form-urlencoded;charset=UTF-8",
			async : true, // 同步  true 异步。默认是异步
			dataType : 'json',
			error : function(resultdata) {
				layer.closeAll();
			},
			success : function(resultdata) {
				layer.closeAll();
				if (resultdata.returnCode == "0000") {
					layer.alert('操作成功', {
						icon : 1
					}, function() {
						parent.editReturn();
						//layer.closeAll(); 
						//layer.closeAll();
						//window.location.href="${pageContext.request.contextPath}/distrbutor/inventory/index";
					});
				} else {
					layer.alert(resultdata.returnMessage);
				}
			}
		});
	}
	function backIndex() {
		parent.editReturn();
	}
</script>
</html>
